package com.donnie.interview.testVolatile;/**
 * @ClassName: TestVolatileVisible
 * @Author: Donnie
 * @Date: 2021/7/15 17:14
 * @Description:
 */

class MyData {
    volatile int number = 0;

    public void addTo60() {
        this.number = 60;
    }
}

/**
 * @ClassName: TestVolatileVisible
 * @Author: DonnieChen
 * @Date: 2021/7/15 17:14
 * @Description:
 */
public class TestVolatileVisible {

    public static void main(String[] args) {
        MyData myData = new MyData();

        new Thread(() -> {
            try {
                Thread.sleep(2000) ;

                myData.addTo60();
                System.out.println("number : " + myData.number);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } , "thread1").start();

        new Thread(() -> {
            myData.number = 61;

            System.out.println("number : " + myData.number);
        }, "thread2").start();

        System.out.println("当前线程名：" + Thread.currentThread().getName());
    }

}
